import {action} from 'mobx'
import * as service from './service'
import {error} from '../error'

// 包含同步和异步的action
// 由于异步action有async前缀，所以同步异步的action很容易区分，所以没有对两种action分文件存放
export default class Actions {

    constructor(state) {
        this.state = state
    }
    @action.bound doReset() {
        this.state.account.firstName = ''
        this.state.account.lastName = ''
    }

    @action.bound
    setValue(key, event) {
        this.state.account[key] = event.target.value;
    }

    @action.bound async login() {
        this.state.account.firstName = 'loading...'
        const ret = await service.login()
        this.state.account.firstName =ret
        error.throwError({
            info: 'login error',
            code: '1001',
            from: 'stores\\login\\actions.js-login'
        })
    }
}